Skip to content

feat: add new gh-files-set module#970

Open
frmadem wants to merge 44 commits intomainfrom
feat/969-poc-gh-files-set
Open

feat: add new gh-files-set module#970
frmadem wants to merge 44 commits intomainfrom
feat/969-poc-gh-files-set

Conversation

@frmadem
Copy link
Contributor

@frmadem frmadem commented Mar 8, 2026

solves #969

@frmadem frmadem requested a review from a team as a code owner March 8, 2026 19:43
@frmadem frmadem linked an issue Mar 8, 2026 that may be closed by this pull request
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Terraform module (modules/gh-files-set) intended to manage a set of files in GitHub repositories (issue #969), and wires it into the repo’s release automation configuration.

Changes:

  • Added new gh-files-set Terraform module using github_repository_file to manage multiple files via a single config object.
  • Added module docs scaffolding (terraform-docs config + header/footer content) and a basic example YAML input.
  • Registered the new module package in release-please-config.json.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
release-please-config.json Registers modules/gh-files-set as a release-please package.
modules/gh-files-set/main.tf Implements managed vs “user-managed” GitHub repository files.
modules/gh-files-set/variables.tf Defines the config input schema + validations.
modules/gh-files-set/outputs.tf Exposes a list of user-managed file paths.
modules/gh-files-set/versions.tf Declares GitHub provider requirement (missing required Terraform version constraint).
modules/gh-files-set/docs/header.md Module overview and usage snippet for terraform-docs injection.
modules/gh-files-set/docs/footer.md Footer content for terraform-docs injection (currently includes scaffolding/code fences).
modules/gh-files-set/README.md Generated/injected docs (currently out of sync with module interface/resources/outputs).
modules/gh-files-set/.terraform-docs.yml terraform-docs configuration for README generation.
modules/gh-files-set/_examples/basic/files.yaml Example input YAML (currently does not match the module input schema).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Terraform module (modules/gh-files-set) intended to manage a set of files in a GitHub repository (issue #969), and wires it into the repo’s release-please module list.

Changes:

  • Added gh-files-set Terraform module (GitHub provider, variables/outputs, example, terraform-docs config, generated README).
  • Added module docs scaffolding (docs/header.md, docs/footer.md) and a basic YAML example.
  • Registered the module in release-please-config.json.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
release-please-config.json Registers modules/gh-files-set as a release-please package.
modules/gh-files-set/versions.tf Declares the GitHub provider requirement for the new module.
modules/gh-files-set/variables.tf Defines the module’s config schema and validations.
modules/gh-files-set/main.tf Implements managed vs “userManaged” GitHub repository file resources.
modules/gh-files-set/outputs.tf Exposes a list of “userManaged” file identifiers.
modules/gh-files-set/docs/header.md Module documentation header content for terraform-docs.
modules/gh-files-set/docs/footer.md Module documentation footer content for terraform-docs.
modules/gh-files-set/_examples/basic/files.yaml Provides a YAML example intended for yamldecode(...) input.
modules/gh-files-set/README.md Generated terraform-docs README for the module.
modules/gh-files-set/.terraform-docs.yml terraform-docs configuration for generating the module README.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +23 to +39
# User-managed files — provision once + ignore content drift
resource "github_repository_file" "user_managed" {
for_each = {
for f in var.config.files : "${f.repository}/${f.file}/${f.branch}" => f
if f.userManaged
}

repository = data.github_repository.this.name
branch = each.value.branch
file = each.value.file
content = each.value.content
commit_message = each.value.commitMessage
overwrite_on_create = each.value.overwriteOnCreate

lifecycle {
ignore_changes = [content]
}
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The “user-managed files — provision once + ignore content drift” behavior isn’t achieved by ignore_changes = [content]: these resources will still be destroyed on terraform destroy, and changes to other arguments (e.g., commit_message, branch, file) will still drive updates/replacements. If the intent is only to ignore content drift, update the comment/docs accordingly; if the intent is to keep files on destroy/provision-once semantics, the implementation needs to change (and likely can’t be fully achieved with github_repository_file alone without impacting destroy behavior).

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot how we could avoid user-managed files to be destroyed on terraform destroy, but without blocking the destroy process, that is, the terraform state should be destroyed without altering the file's contents, please implement it if you see a solution.

@frmadem frmadem requested a review from alambike March 21, 2026 00:20
frmadem and others added 5 commits March 21, 2026 01:20
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +23 to +28
# User-managed files — provision once + ignore content drift
resource "github_repository_file" "user_managed" {
for_each = {
for f in var.config.files : "${f.file}/${f.branch}" => f
if f.userManaged
}
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says “provision once” for user_managed, but this resource will still be updated whenever non-ignored arguments change (e.g., commitMessage, overwriteOnCreate) and it will be deleted on destroy. Either align the comment/docs with the actual behavior, or expand the lifecycle settings/design to truly match “provision once / survive destroy”.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

frmadem and others added 5 commits March 21, 2026 01:48
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment on lines +23 to +39
# User-managed files — provision once + ignore content drift
resource "github_repository_file" "user_managed" {
for_each = {
for f in var.config.files : "${f.repository}/${f.file}/${f.branch}" => f
if f.userManaged
}

repository = data.github_repository.this.name
branch = each.value.branch
file = each.value.file
content = each.value.content
commit_message = each.value.commitMessage
overwrite_on_create = each.value.overwriteOnCreate

lifecycle {
ignore_changes = [content]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot how we could avoid user-managed files to be destroyed on terraform destroy, but without blocking the destroy process, that is, the terraform state should be destroyed without altering the file's contents, please implement it if you see a solution.

Copy link
Contributor

Copilot AI commented Mar 21, 2026

@alambike I've opened a new pull request, #1107, to work on those changes. Once the pull request is ready, I'll request review from you.

Co-authored-by: Javier Gómez Rodríguez <javier.gomez@prefapp.es>
@frmadem
Copy link
Contributor Author

frmadem commented Mar 21, 2026

#970 (comment)

@alambike this problem is resolved by removing the files with a tofu state rm <address of the file's resource>.

The solution is working and has been tested.

https://github.com/prefapp/gitops-k8s/blob/2809a90c370f029ff9e0fcffd21c7250af752b30/packages/gh_provisioner/src/entities/ghfeature/index.ts#L58-L104

@frmadem
Copy link
Contributor Author

frmadem commented Mar 21, 2026

#970 (comment)

@alambike this problem is resolved by removing the files with a tofu state rm <address of the file's resource>.

The solution is working and has been tested.

https://github.com/prefapp/gitops-k8s/blob/2809a90c370f029ff9e0fcffd21c7250af752b30/packages/gh_provisioner/src/entities/ghfeature/index.ts#L58-L104

Besides the copilot solution seems to fail: https://github.com/jvazquez-prefapp/state-github/runs/68045393156?check_suite_focus=true

@frmadem frmadem requested a review from alambike March 22, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

POC gh files set

4 participants